import axios from "axios";
import querystringify from "querystringify";

const instance = axios.create({
    timeout:5000
})

export default instance;

//发送数据之前,进行处理
instance.interceptors.request.use(
    config =>{   
        if(config.methods === "post"){
            config.data = querystringify.stringify(config.data);
        }
        return config;
    },
    error =>{
        return Promise.reject(error);
    }
)
//获取数据之前的处理
instance.interceptors.response.use(
    response =>{
        return response.status === 200 ? Promise.resolve(response) : Promise.reject(response);
    },
    error =>{
        return Promise.reject(error)
    }
)